﻿using System.Security.Cryptography;

namespace SvGame.Logic;

public static partial class GameLogic
{
    public static bool PackGetPlayer(this MyPackage pack, out Player? player)
    {
        player = pack.GetObj<Player>();
        if (player == null)
        {
            pack.Err(EProtocolResult.请先登录);
            return false;
        }
        if (player.Comb.LiveState != ELiveState.Living)
        {
            pack.Err(EProtocolResult.你现在不存活);
            return false;
        }
        return true;
    }
    public static bool PackGetLoginPlayer(this MyPackage pack, out Player? player)
    {
        player = pack.GetObj<Player>();
        return player != null;
    }
    public static PlayerInfoBase InfoBase(this Player player)
    {
        var info = new PlayerInfoBase();
        info.Puid = player.Puid;
        info.UserId = player.Uuid;
        info.Gender = (int)player.Gender;
        info.Name = player.Name;
        info.Head = player.Head;
        info.Family = player.Family;
        info.Guild = player.Guild;
        info.Title = player.Title;
        info.Age = player.Age;
        info.Level = player.Level;
        info.Exp = player.Exp;
        info.Gold = player.Gold;
        info.Gem = player.Gem;
        info.Pot = player.Pot;
        return info;
    }
    public static PlayerInfoMisc InfoMisc(this Player player)
    {
        var info = new PlayerInfoMisc();
        return info;
    }
    public static void NtfPlayerInfo(this Player player)
    {
        var nrf = new G2CNtfPlayerInfo();
        nrf.InfoBase = player.InfoBase();
        nrf.InfoMisc = player.InfoMisc();
        player.Send(nrf);
    }
    public static void NtfScore(this Player player)
    {
        var nrf = new G2CNtfScore();
        nrf.InfoStatus = player.InfoStatus();
        nrf.InfoTalent = player.InfoTalent();
        player.Send(nrf);
    }
    public static void NtfHp(this Player player)
    {
        var nrf = new G2CNtfHp();
        nrf.InfoStatus = player.InfoStatus();
        player.Send(nrf);
    }
    public static RoomInfoPlayer GetRoomInfoPlayer(this Player obj)
    {
        var info = new RoomInfoPlayer();
        info.Puid = obj.Puid;
        info.Name = obj.Name;
        return info;
    }
}
